package com.example.shop_car_2208.comment

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.shop_car_2208.entity.CommentEntityResult
import com.example.shop_car_2208.entity.HUIFUCommentParam
import com.example.shop_car_2208.entity.ParamComment
import com.example.shop_car_2208.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CommentViewModel:BaseViewModel() {
    val CommentSuccess = MutableLiveData<CommentEntityResult>()
    val CommentFail = MutableLiveData<String>()

    fun getComment(){
        viewModelScope.launch {
            try {
                CommentSuccess.value = apiService.getComment()
            }catch (e:Exception){
                CommentFail.value = e.message
            }
        }
    }

    val getchildSuccess =MutableLiveData<CommentEntityResult>()
    val getChildFail = MutableLiveData<String>()
    fun getChild(rootId:Int){
        viewModelScope.launch {
            try {
                getchildSuccess.value = apiService.getChildComment(rootId)
            }catch (e:Exception){
                getChildFail.value = e.message
            }
        }
    }
    val ttCommentSuccess = MutableLiveData<CommentEntityResult>()
    val ttcommentFail = MutableLiveData<String>()
    fun getComment(msg:String){
        viewModelScope.launch {
            try {
                val param = ParamComment(msg,103)
                ttCommentSuccess.value = apiService.Comment(param)
            }catch (e:Exception){
                ttcommentFail.value = e.message
            }
        }
    }
    val HUIFUCommentSuccess = MutableLiveData<CommentEntityResult>()
    val HUIFUCommentFail = MutableLiveData<String>()
    fun getHFComment(msg:String,id:Int){
        viewModelScope.launch {
            try {
                val param = HUIFUCommentParam(msg,id,103)
                HUIFUCommentSuccess.value = apiService.HFComment(param)
            }catch (e:Exception){
                HUIFUCommentFail.value = e.message
            }
        }
    }
}